<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>九大隐式对象之pageContext</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	pageContext这个对象代表页面上下文，该对象主要用于访问jsp之间的共享数据。
	<br> 1，使用pageContext可以访问page，request，session，application范围的变量。
	<br> 提供力两个方法
	<br> getAttribute（String name）：获得page范围内的name属性。
	<br> getAttribute（String name，int
	scope）；取得指定范围内的name属性，其中scope可以有如下四个值
	<br> PageContext.PAGE_SCOPE:对应于page的范围。
	<br>
	PageContext.REQUEST,PageContext.SESSION,PageContext.APPLICATION四个值
	<br> 与getAttribute方法相对应，PageContext也提供了 setAttribute方法。

	<br> 分别用pageContext和四个对象域设置
	<br>
	<%
    pageContext.setAttribute("page","hellow_page");
    
    request.setAttribute("request", "hellow_request");
    pageContext.setAttribute("request2","hellow_request2",PageContext.REQUEST_SCOPE);
    
    session.setAttribute("session", "hellow_session");
    pageContext.setAttribute("session2","hellow_seesion2",PageContext.SESSION_SCOPE);
    
    application.setAttribute("application", "hellow_application");
    pageContext.setAttribute("application2","hellow_application2",PageContext.APPLICATION_SCOPE);
    
     %>

	<%
     
      printScope(out,pageContext,"page");
      
      printScope(out,pageContext,"request");
      
      printScope(out,pageContext,"request2");
      
      printScope(out,pageContext,"session");
      
      printScope(out,pageContext,"session2");
      
      printScope(out,pageContext,"application");
      
      printScope(out,pageContext,"application2");
     
      %>

	<%!
      
      private void printScope(JspWriter out,PageContext pageContext,String name) throws Exception{
      
      
      
           out.println(name+"所在范围:"+pageContext.getAttributesScope(name)+"<br>");
      
      
      }
      
      
       %>
       
       <br>
       <br>
       2.pageContext还可用于获得其他内置对象，pageContext对象包含如下方法。<br>
       ServletRequest getRequest();获得request对象<br>
       ServletResponse getResponse（）；获得response对象<br>
       ServletConfig getServletConfig（）；获得config对象<br>
       ServletContext getServletContext（）；获得application对象<br>
       HttpSession getSession（）；获得session对象<br>
       因此一旦在jsp，servlet编程中获取了pageContext对象，就可以通过它提供的上面方法来获取其它内置对象



</body>
</html>
